<template>
  <div class="app-container">
    <!--账单管理-待核对账单-->
    <div class="top">
      <h5 class="title">待核对账单</h5>
      <div class="nav">
        <el-button type="primary" round style="width: 120px;height: 36px;font-size: 14px">匹配发票</el-button>
        <el-button type="primary" round style="width: 120px;height: 36px;font-size: 14px">发布对账</el-button>
        <el-button type="primary" round style="width: 120px;height: 36px;font-size: 14px" @click="dialogVisible = true">对账</el-button>
        <el-button type="primary" round style="width: 120px;height: 36px;font-size: 14px" @click="adjust">调整审核</el-button>
        <el-button type="primary" round style="width: 120px;height: 36px;font-size: 14px">未完成账单</el-button>
        <el-button type="primary" round style="width: 120px;height: 36px;font-size: 14px" @click="record">反记</el-button>
      </div>
      <div class="nav">
        <el-input
          v-for="(item,index) in iptStyle"
          :key="index"
          style="width: 200px;height: 36px;margin-right: 10px;"
          :placeholder="item.str"
          :suffix-icon="item.icon"
        >
        </el-input>
      </div>
      <div class="nav">
        <el-button type="primary" round style="width: 120px;height: 36px;font-size: 14px">搜索</el-button>
        <el-button type="primary" round style="width: 120px;height: 36px;font-size: 14px">导出</el-button>
      </div>
    </div>
    <div class="bottom">
      <el-table ref="table" :data="tableData" @selection-change="handleSelectionChange" size="small" style="width: 100%;">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" width="159" label="账单编号"></el-table-column>
        <el-table-column prop="groupName" width="159" label="机构/集团"></el-table-column>
        <el-table-column prop="areaId" width="159" label="所属区域"></el-table-column>
        <el-table-column prop="salesId" width="159" label="所属销售"></el-table-column>
        <el-table-column prop="clinicName" width="159" label="诊所/机构名称"></el-table-column>
        <el-table-column  width="100" prop="packageGroupList" label="病例数">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.packageGroupList" :key="index">
              <span>{{ item.patientsCount }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column  width="100" prop="packageGroupList" label="套餐类型">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.packageGroupList" :key="index">
              <span>{{ item.packageName }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column  width="100" prop="packageGroupList" label="疗程单价">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.packageGroupList" :key="index">
              <span>{{ item.amont }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="amountSum" width="159" label="金额"></el-table-column>
        <el-table-column prop="adjustAmountSum" width="159" label="调整金额"></el-table-column>
        <el-table-column prop="invoiceAmountSum" width="159" label="开票总额"></el-table-column>
        <el-table-column prop="settlePeriod" width="159" label="结算周期"></el-table-column>
        <el-table-column prop="invoiceType" width="159" label="发票类型"></el-table-column>
        <el-table-column prop="invoiceItem" width="159" label="发票项目"></el-table-column>
        <el-table-column prop="invoiceTitle" width="159" label="公司名称"></el-table-column>
        <el-table-column prop="creditCode" width="159" label="纳税人识别号"></el-table-column>
        <el-table-column prop="invoiceAddress" width="159" label="地址"></el-table-column>
        <el-table-column prop="invoiceMobile" width="159" label="电话"></el-table-column>
        <el-table-column prop="invoiceBankName" width="159" label="开户行"></el-table-column>
        <el-table-column prop="invoiceAccNumber" width="159" label="帐号"></el-table-column>
        <el-table-column prop="invoiceRemark" width="159" label="发票备注"></el-table-column>
        <el-table-column prop="invoiceRecieverName" width="159" label="邮寄接收人"></el-table-column>
        <el-table-column prop="clinicMobile" width="159" label="邮寄电话"></el-table-column>
        <el-table-column prop="clinicAddress" width="159" label="邮寄地址"></el-table-column>
        <el-table-column prop="invoiceEmail" width="159" label="邮箱"></el-table-column>
        <el-table-column prop="expressCode" width="159" label="顺丰快递单号"></el-table-column>
        <el-table-column prop="invoiceCode" width="159" label="发票号码"></el-table-column>
        <el-table-column prop="adjustRemark" width="159" label="调账说明"></el-table-column>
        <el-table-column prop="adjustStatus" width="159" label="调账审核"></el-table-column>
        <el-table-column prop="remark" width="159" label="对账说明"></el-table-column>
        <el-table-column prop="blocAdmin" width="135" label="操作">
          <template slot-scope="scope">
            <a
              style="color: #719DC9;text-decoration:underline"
              @click="edit(scope.row)"
            >编辑账单</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 对账弹窗 -->
    <el-dialog
      title="对账"
      :visible.sync="dialogVisible"
      width="632"
      :before-close="handleClose">
      <el-form class="form" ref="form" :model="form">
        <el-form-item>
          <el-radio-group v-model="form.resource">
            <el-radio label="账单无误，待开发票"></el-radio>
            <el-radio label="账单有误"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-input type="textarea" placeholder="请错误描述" v-model="form.desc"></el-input>
        </el-form-item>
        <el-form-item class="btn">
          <el-button>取消</el-button>
          <el-button type="primary" @click="onSubmit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getVerifyBill, getCheckingBill, clearBillingBusiness, getBillingDetail } from '@/api/oper';
import { getDictMap } from '@/api/system/dictDetail';
const dict = ['invoice_type']

export default {
  data() {
    return {
      btnStr: ['创建门诊', '编辑门诊', '规则配置', '暂停合作', '导出诊所'],
      iptStyle: [
        {
          str: '搜诊所/代理商名称、诊所/机构联系人、诊所/机构电话',
          icon: 'el-icon-search'
        },
        {
          str: '所属区域',
          icon: 'el-icon-arrow-down'
        },
        {
          str: '所属销售',
          icon: 'el-icon-arrow-down'
        },
        {
          str: '诊所名称',
          icon: 'el-icon-arrow-down'
        },
        {
          str: '发票类型',
          icon: 'el-icon-arrow-down'
        }
      ],
      tableData: [],
      dialogVisible: false,
      multipleSelection: [],
      form: {
        resource: '',
        desc: ''
      }
    };
  },
  created() {
    getVerifyBill().then(res => {
      this.tableData = res.content;
    });
    dict.forEach(item => {
      getDictMap(item).then((e) => {
        console.log(e, 'eee')
        this.item = e.package_rule
      });
    })
  },
  methods: {
    blocDetail(row) {
      this.$router.push('details');
    },
    // 对账提交
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          getCheckingBill({
            billingIdList: this.multipleSelection
          }).then(res => {
            consoel.log(res)
          })
          alert('submit!');
        } else {
          return false;
        }
      });
    },
    // 反记
    record() {
      clearBillingBusiness({
        billingIds: []
      }).then(res => {
        console.log(res, 'res')
      })
    },
    // 编辑账单
    edit(info) {
      this.$router.push(`billDetails?id=${info.id}`)
    },
    adjust() {
      const billingIds = this.multipleSelection.map(i => Number(i.id))
      console.log(billingIds, 'billingIds')
      getBillingDetail({
        billingIds: JSON.stringify(billingIds)
      }).then(res => {
        console.log(res, 'eeee')
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleClose() {
      this.dialogVisible = false
    }
  }
};
</script>

<style scoped>
    .top {
      height: 210px;
    }
    .top .title {
      margin: 0 0 20px;
      font-size: 30px;
      color: #02a7f0;
    }

    .nav {
      margin-top: 10px;
      display: flex;
    }

    .text {
      font-size: 18px;
      font-weight: bold;
      color: #333;
    }

    .bottom {
      margin-top: 10px;
    }

    .form {
      padding: 0 50px;
    }

    .form .btn {
      text-align: right;
    }
</style>
